var express = require('express');
var router = express.Router();
const pool = require('../pool');
/* GET home page. */
// 1.查看商品种类 get 127.0.0.1:3000/family
router.get('/family', (req, res, next) =>{
  pool.query("select * from lrw_laptop_family",(err,result)=>{
	  console.log(result);
	  res.json(result);
  })
});
//2.查看所有商品信息
router.get("/products",(req,res,next)=>{
	pool.query("select * from lrw_laptop",(err,result)=>{
		console.log(result);
		res.json(result);
	})
})
// 3.根据编号查看商品信息
router.get(`/product/:lid`,(req,res,next)=>{
	let obj=req.params;
	console.log(obj);
	pool.query('select * from lrw_laptop where lid = ?',[obj.lid],(err,result)=>{
		res.json(result);
	})
})

// 3.根据编号查看商品补充信息 (下部)
router.get(`/products/:laptop_id`,(req,res,next)=>{
	let obj=req.params;
	console.log(obj);
	pool.query('select * from lrw_laptop_pic where laptop_id = ?',[obj.laptop_id],(err,result)=>{
		res.json(result);
	})
})

// 4.查看地址表 
router.get(`/address`,(req,res,next)=>{
	pool.query('select * from lrw_receiver_address',(err,result)=>{
		res.json(result);
	})
})
//5.添加地址
router.post(`/addplace`,(req,res,next)=>{
	let obj=req.body;
	console.log(obj);
	pool.query('insert into lrw_receiver_address set ?',[obj],(err,result)=>{
		res.json(result);
	})
})
//6.查看轮播
router.get(`/lunbo`,(req,res,next)=>{
	pool.query('select * from lrw_carousel',(err,result)=>{
		console.log(result)
		res.json(result);
	})
})












module.exports = router;
